// pages/t_course/t_course.js
import request from '../../request/request.js'
Page({
  data: {
    active: 1,
    date: '',
    show: false,
    courseList:[],
    minDate: new Date().getTime()-1000*60*60*24*30,
    coachInfo:''
  },
  onChange(event) {
    // event.detail 的值为当前选中项的索引
    if(event.detail===0){
      wx.redirectTo({
        url: '../t_index/t_index'
      });
    }
    if(event.detail===2){
      wx.redirectTo({
        url: '../t_user/t_user'
      });
    }   
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let coachInfo = wx.getStorageSync('coachInfo');
    this.setData({coachInfo:coachInfo})
    this.getCourseList();
  },

  onDisplay() {
    this.setData({ show: true });
  },
  onClose() {
    this.setData({ show: false });
  },
  formatDate(date) {
    date = new Date(date);
    return `${date.getFullYear()}/${date.getMonth() + 1}/${date.getDate()}`;
  },
  onConfirm(event) {
    console.log(event);
    
    this.setData({
      show: false,
      date: this.formatDate(event.detail),
    });
    this.getCourseList()
  },
  getCourseList(){
    var that=this;
    console.log(this.data);
    
    request({
      url:'course/list',
      data:{
        date:that.data.date,
        coachId:that.data.coachInfo.id
      },
      method:'post'
    }).then(res=>{
      this.setData({
        courseList:res.data.data
      })
    }).catch(err=>{})
  }
})